<template lang="">
        <div>
            <myheader />
            <reply :data='catelist'/>
            <van-field label="课程标题" v-model="title" />

            <van-field label="课程描述" v-model="content" rows="5" type="textarea" />
            <van-field v-for='(value,key) in params' :label="value" v-model="info[key]"  :key='key'/>

              <van-button round block type="info" style='width:200px' @click='add'>提交</van-button>
        </div>
    </template>
    <script>
    import myheader from '@/components/myheader'
    import reply from '@/components/test/reply'
    import bus from './bus.js';
    export default {
        data(){
            return{
                catelist:{},
                title:'',
                content:'',
                cid:0,
                params:{},
                info:{}
            }
        },
        methods: {
            add(){
                //遍历info
                var list=[]
                for(var k in this.info){
                    list.push({'key':k,'value':this.info[k],'label':this.params[k]})
                }
                var list_str = JSON.stringify(list)
                let data={'title':this.title,'cid':this.cid,'content':this.content,'params':list_str}
                // let pid = localStorage.getItem('pid')
                // if(pid){
                //     this.cid = pid
                // }
                this.$axios.post('course/courseM',data).then(res=>{
                    
                })
            },
            getCatelist(){
            this.$axios.get('course/cateM').then(res=>{
                this.catelist = {'id':0,'name':'顶级','son':res.data.list}
                console.log(this.catelist)
            })
        }
        },
        mounted() {
        
        this.getCatelist()
    },
        components:{
            'myheader':myheader,
            'reply':reply
        },
        created() {
            bus.$on('cid',value=>{
                this.cid = value
                //动态渲染
                //根据id获取分类参数
                this.$axios.get('course/getCateById?id='+value).then(res=>{
                    this.params = JSON.parse(res.data.params)
                })
               
            })
        },
    }
    </script>
    <style lang="">
        
    </style>